package com.laolang.shop.modules.sys.web.admin;

import com.laolang.shop.common.core.consts.ModuleNameConst;
import com.laolang.shop.common.core.util.LogUtil;
import com.laolang.shop.modules.auth.util.SecurityUtil;
import com.laolang.shop.modules.sys.logic.admin.SysMenuAdminLogic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author khlbat
 * @version 1.0
 * @date 2020/11/1 20:46
 */
@Slf4j
@RequestMapping("admin/sys/sysmenu")
@Controller
public class SysMenuAdminController {

    @Autowired
    private SysMenuAdminLogic sysMenuAdminLogic;

    @PreAuthorize("@adminPerm.isAdmin(authentication)")
    @ResponseBody
    @GetMapping("info")
    public Map<String, Object> info() {
        LogUtil.info(log, ModuleNameConst.SYS, SecurityUtil.getUserId().toString());
        Map<String, Object> map = new HashMap<>();
        map.put("id", 1001L);
        map.put("title", "系统设置");
        map.put("code", "sys_menu");
        return map;
    }

    @PreAuthorize("@adminPerm.isAdmin(authentication) and hasAuthority('ROLE_ADMIN_SYS_MENU')")
    @ResponseBody
    @GetMapping("info2")
    public Map<String, Object> info2() {
        LogUtil.info(log, ModuleNameConst.SYS, SecurityUtil.getUserId().toString());
        Map<String, Object> map = new HashMap<>();
        map.put("id", 1001L);
        map.put("title", "系统设置");
        map.put("code", "sys_menu");
        return map;
    }

    @PreAuthorize("@adminPerm.isAdmin(authentication) and hasAuthority('ROLE_ADMIN_SYS_ROLE')")
    @ResponseBody
    @GetMapping("info3")
    public Map<String, Object> info3() {
        LogUtil.info(log, ModuleNameConst.SYS, SecurityUtil.getUserId().toString());
        Map<String, Object> map = new HashMap<>();
        map.put("id", 1001L);
        map.put("title", "系统设置");
        map.put("code", "sys_menu");
        return map;
    }
}
